const App = {
    mixins: [Save],//配置文件，路径/utils/mixins.js
    data() {
        return {
            childDataForm1: [{}],
            category: [],
            village: [],
            cityValue: [],
            personal_information: [],
            Natural_Resource_Tag: [],
            Natural_Resource_Usage: [],
            Natural_Resource_Usage1: [],
            Usage_status: [{ label: '空闲', value: '0' }, { label: '占用', value: '1' }, { label: '租用', value: '2' }],
            village_Collective: [],
        };
    },
    mounted() {
        this.getCategory();
    },
    watch: {
        Usage(val) {
            if (this.action == 'Modify') {
                this.cityValue = val;
            }
        },
        'dataForm.Village_Collective_SerialNumber'(val) {
            if (this.action == 'Modify') {
                this.changeVillage(this.dataForm.Village_SerialNumber);
            }
        }
    },
    computed: {
        Usage() {
            if (this.action == 'Modify') {
                let obj = this.Natural_Resource_Usage1.filter(i => i.Natural_Resource_Usage_SerialNumber == this.dataForm.Natural_Resource_Usage_SerialNumber)[0]
                if (obj) {
                    return [obj.Parent_SerialNumber, obj.Natural_Resource_Usage_SerialNumber]
                }
            }
        }
    },
    methods: {
        changeVillage(val) {
            console.log(val);
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'village_collective',
                    Condition: "Row_Status='0' AND VillageNumber='" + val + "'"
                },
                success: (data) => {
                    this.village_Collective = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
        },
        getCategory() {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'natural_resources_category',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.category = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryForObtainingTrees`,
                type: "GET",
                data: {
                    TableName: 'natural_resources_usage',
                    NodeCode: '',
                },
                success: (data) => {
                    this.Natural_Resource_Usage = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'natural_resources_usage',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.Natural_Resource_Usage1 = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'natural_resources_tags',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.Natural_Resource_Tag = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'personal_information',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.personal_information = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'base_system_village',
                    Condition: "TownNumber LIKE '232723%'",
                },
                success: (data) => {
                    this.village = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
        },
        changeAddress(val) {
            console.log("地址值变化了:", val);
            if (!val || this.cityValue1.length === 0) {
                this.dataForm.Coord = "";
                return;
            }
            // 开始加载状态
            this.loading = true;
            console.log("地址值变化，开始解析坐标...");

            let Province = this.city.filter((i) => i.value == this.cityValue[0])[0];
            let City = Province.children.filter(
                (i) => i.value == this.cityValue[1]
            )[0];
            let County = City.children.filter((i) => i.value == this.cityValue[2])[0];
            let Town = this.city1.filter(
                (i) => i.ProvinceNumber == this.cityValue1[0]
            )[0];
            // let village = Town.children.filter(
            //   (i) => i.ProvinceNumber == this.cityValue1[1]
            // )[0];
            let Address =
                Province.label +
                City.label +
                County.label +
                Town.Province +
                // village.Province +
                val;
            if (Address) {
                $.ajax({
                    url: `${y}/getAddressResolutionAction`,
                    type: "get",
                    data: {
                        Address: Address,
                    },
                    success: (data) => {
                        console.log(data);
                        console.log(data.Data);
                        console.log(Address);
                        // return;
                        // localSearch.setSearchCompleteCallback((searchResult) => {
                        var poi = data.Data;
                        console.log(poi);

                        let a = poi.lng + "," + poi.lat;
                        console.log(a);

                        if (a) {
                            console.log(a);

                            // 获取BD-09坐标
                            const bd09Lng = poi.lng;
                            const bd09Lat = poi.lat;

                            // 转换为WGS-84坐标
                            const wgs84 = bd09ToWGS84(bd09Lng, bd09Lat);
                            console.log(wgs84);
                            // 腾讯2000
                            const gcj02 = bd09ToGCJ02(bd09Lng, bd09Lat);
                            console.log(gcj02);
                            this.dataForm.dhCoord = "[" + gcj02.lng + "," + gcj02.lat + "]";

                            this.dataForm.Coord = "[" + wgs84.lng + "," + wgs84.lat + "]";
                            console.log(this.dataForm.Coord);
                            this.loading = false;
                        } else {
                            alert("未找到该地址！");
                        }
                    },

                    dataType: "json",
                });
            }
        },
        changeCity(val) {
            this.dataForm.Natural_Resource_Usage_SerialNumber = val[val.length - 1];
        },
    },
};
const { createApp, ref } = Vue;
const app = createApp(App);
app.use(ElementPlus, { locale: zhCn });
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
//自定义组件
app.component('yl-upload', ylUpload);
const ElMessage = ElementPlus.ElMessage;
app.mount("#app");
